package com.wtwd.campus.utils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.wtwd.campus.common.Constants;
import com.wtwd.campus.common.RespCode;
import com.wtwd.campus.common.RespCodeEntity;
import com.wtwd.campus.dao.CommandRecordMapper;
import com.wtwd.campus.dao.OffLineBufferCmdMapper;
import com.wtwd.campus.entity.*;
import com.wtwd.campus.service.IRMFeignClientService;
import com.wtwd.campus.service.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * @Author ldaoliang
 * @Date create in 14:11 2021/6/10
 * @Description 用户有按钮的，需要操作用户id，设备是否在线
 */
@Component
public class CommandSendUtils {

    private static final Logger logger = LoggerFactory.getLogger(CommandSendUtils.class);

    @Autowired
    private RedisService redisService;
    @Autowired
    private IRMFeignClientService irmFeignClientService;
    @Autowired
    private OffLineBufferCmdMapper offLineBufferCmdMapper;
    @Autowired
    private CommandRecordMapper commandRecordMapper;


    /**
     * 判断设备是否在线
     *
     * @param imei 设备imei
     * @return 设备是否在线
     */
    public boolean deviceOnline(String imei) {
        boolean isOnline = redisService.hasKey(Constants.DEVICE_ONLINE_PREFIX + imei);
        logger.info("设备:【{}】: {}", imei, isOnline ? "在线" : "离线");
        return isOnline;
    }


    /**
     * 查询设备定位（只做在线发送）
     *
     * @param imei          设备imei号
     * @param commandNumber 指令流水号
     * @return 发送或者缓存成功
     */
    public boolean queryDeviceLocation(String imei, String commandNumber, Integer userId, boolean isOnline, boolean offSendLine) {
        String content = "查询设备".concat("的定位信息");
        saveOnlineSendCommandRecord(imei, Constants.ACTIVE_DEVICE_LOCATION, content, commandNumber, userId, null);
        //进行指令的远程调用下发
        RespCodeEntity respCodeEntity = irmFeignClientService.queryDeviceLocation(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【查询设备定位】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 查询设备参数
     *
     * @param imei 设备imei号
     * @return 发送是否成功
     */
    public boolean getDeviceParam(String imei, String commandNumber, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "查询设备参数";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.DEVICE_PARAMETERS, commandNumber);
        } else {
            if (isOnline) {
                // 1.如果在线，则在线发送且存储下发记录
                saveOnlineSendCommandRecord(imei, Constants.DEVICE_PARAMETERS, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.DEVICE_PARAMETERS, content, userId, null, commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.queryDeviceParam(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【查询设备参数】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 查询Iccid和simCard号
     *
     * @param imei          设备imei号
     * @param commandNumber 指令流水号
     * @return 发送是否成功
     */
    public boolean getDeviceIccidAndSimCardNo(String imei, String commandNumber, Integer userId, Boolean isOnline, Boolean offLineSend) {
        String content = "查询Iccid和simCard号";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.ICCID_AND_SIM, commandNumber);
        } else {
            if (isOnline) {
                // 1.如果在线，则在线发送且存储下发记录
                saveOnlineSendCommandRecord(imei, Constants.ICCID_AND_SIM, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.ICCID_AND_SIM, content, userId, null, commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.queryDeviceIccidAndSimCardNo(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【查询设备iccid和SimCard号】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 查询设备Imeid
     *
     * @param imei          设备imei号
     * @param commandNumber 指令流水号
     * @return 发送是否成功
     */
    public boolean getDeviceImeid(String imei, String commandNumber, Integer userId, Boolean isOnline, Boolean offLineSend) {
        String content = "查询设备Imeid";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.DEVICE_IMEID, commandNumber);
        } else {
            if (isOnline) {
                // 1.如果在线，则在线发送且存储下发记录
                saveOnlineSendCommandRecord(imei, Constants.DEVICE_IMEID, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.DEVICE_IMEID, content, userId, null, commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.queryDeviceImeid(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【查询设备imeid】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置设备临时ip和端口
     *
     * @param imei
     * @param commandNumber
     * @param ipAddress
     * @param port
     * @return
     */
    public boolean setTempServerIpAndPort(String imei, String commandNumber, String ipAddress, int port, Integer userId, Boolean isOnline, Boolean offLineSend) {
        MqSetIpAndPort mqSetIpAndPort = new MqSetIpAndPort();
        mqSetIpAndPort.setImei(imei);
        mqSetIpAndPort.setCommandNumber(commandNumber);
        mqSetIpAndPort.setIpAddress(ipAddress);
        mqSetIpAndPort.setPort(port);
        mqSetIpAndPort.setRetryTimes(255);
        String content = "设置设备临时ip：".concat(ipAddress).concat(" 和端口：").concat(String.valueOf(port));
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SET_TEMPORARY_CONTROL_CENTER, commandNumber);
        } else {
            if (isOnline) {
                // 1.如果在线，则在线发送且存储下发记录
                saveOnlineSendCommandRecord(imei, Constants.SET_TEMPORARY_CONTROL_CENTER, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SET_TEMPORARY_CONTROL_CENTER, content, userId, JSONObject.toJSONString(mqSetIpAndPort), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setTempIpAndPort(mqSetIpAndPort);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置设备临时服务器地址】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置默认临时ip和端口
     *
     * @param imei
     * @param commandNumber
     * @param ipAddress
     * @param port
     * @return
     */
    public boolean setDefaultServerIpAndPort(String imei, String commandNumber, String ipAddress, Integer port, boolean isOnline, int userId, boolean offLineSend) {
        MqSetIpAndPort mqSetIpAndPort = new MqSetIpAndPort();
        mqSetIpAndPort.setImei(imei);
        mqSetIpAndPort.setCommandNumber(commandNumber);
        mqSetIpAndPort.setIpAddress(ipAddress);
        mqSetIpAndPort.setPort(port);
        mqSetIpAndPort.setRetryTimes(Constants.DEFAULT_RETRY_COUNT);
        String content = "设置默认临时ip：".concat(ipAddress).concat("和端口：").concat(port.toString());
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SET_DEFAULT_CONTROL_CENTER, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SET_DEFAULT_CONTROL_CENTER, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SET_DEFAULT_CONTROL_CENTER, content, userId, JSONObject.toJSONString(mqSetIpAndPort), commandNumber, null);
            }
        }
        //进行指令的远程调用下发
        RespCodeEntity respCodeEntity = irmFeignClientService.setDefaultIpAndPort(mqSetIpAndPort);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置设备默认服务器地址】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }


    /**
     * 设置上报时间间隔
     *
     * @param imei
     * @param commandNumber
     * @param mode
     * @param interval
     * @param isOnline
     * @param userId
     * @return
     */
    public boolean setDeviceMode(String imei, String commandNumber, Integer mode, Integer interval, boolean isOnline, int userId, boolean offLineSend) {
        MqSetWorkMode mqSetWorkMode = new MqSetWorkMode();
        mqSetWorkMode.setImei(imei);
        mqSetWorkMode.setCommandNumber(commandNumber);
        mqSetWorkMode.setMode(mode);
        mqSetWorkMode.setInterval(interval);
        String content = "设置工作模式为：".concat(mode == 1 ? "定位模式" : "省电模式").concat("上报时间间隔:").concat(interval.toString()).concat("秒");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SET_WORK_MODE, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SET_WORK_MODE, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SET_WORK_MODE, content, userId, JSONObject.toJSONString(mqSetWorkMode), commandNumber, null);
            }
        }
        //进行指令的远程调用下发
        RespCodeEntity respCodeEntity = irmFeignClientService.setWorkMode(mqSetWorkMode);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置设备工作模式】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 修改上报时间间隔
     *
     * @param imei
     * @param commandNumber
     * @param interval
     * @return
     */
    public boolean setUploadInterval(String imei, String commandNumber, Integer interval, boolean isOnline, int userId, boolean offLineSend) {
        String content = "设置上报时间间隔:".concat(interval.toString()).concat("秒");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SET_UPLOAD_TIME, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SET_UPLOAD_TIME, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SET_UPLOAD_TIME, content, userId, interval.toString(), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setUpLoadInterval(imei, commandNumber, interval);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【修改上报时间间隔】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 闲时自动切换模式
     *
     * @param imei          设备imei号
     * @param commandNumber 指令序列号
     * @param start         开始时间
     * @param end           结束时间
     * @param flag          开关 0-关闭 1-开启
     * @param isOnline      设备是否在线
     * @param userId        操作用户id
     * @return
     */
    public boolean setSleepTimeAutoChangeMode(String imei, String commandNumber, String start, String end, int flag, boolean isOnline, int userId, boolean offLineSend) {
        MqSleepTimeAutoChange mqSleepTimeAutoChange = new MqSleepTimeAutoChange();
        mqSleepTimeAutoChange.setCommandNumber(commandNumber);
        mqSleepTimeAutoChange.setImei(imei);
        mqSleepTimeAutoChange.setStart(start);
        mqSleepTimeAutoChange.setEnd(end);
        mqSleepTimeAutoChange.setFlag(flag);
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.AUTO_CHANGE_WORK_MODE, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.AUTO_CHANGE_WORK_MODE, "闲时自动切换模式", commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.AUTO_CHANGE_WORK_MODE, "闲时自动切换模式", userId, JSONObject.toJSONString(mqSleepTimeAutoChange), commandNumber, null);
            }
        }
        //进行指令的远程调用下发
        RespCodeEntity respCodeEntity = irmFeignClientService.setSleepTimeAutoChangeMode(mqSleepTimeAutoChange);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【闲时自动切换模式】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置监听号码；设备不在线不发
     *
     * @param imei          设备imei
     * @param commandNumber 指令序列号
     * @param phone         监听号码
     * @param userId        操作用户id
     * @return
     */
    public boolean setMonitorPhone(String imei, String commandNumber, String phone, int userId) {
        saveOnlineSendCommandRecord(imei, Constants.SET_MONITOR_NUMBER, "设置监听号码：".concat(phone), commandNumber, userId, null);
        RespCodeEntity respCodeEntity = irmFeignClientService.setMonitorPhone(imei, commandNumber, phone);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置监听号码】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 添加课堂模式（免打扰协议）
     *
     * @param deviceClassMode 课堂模式对象
     * @param isOnline        设备是否在线
     * @param userId          操作用户Id
     * @return
     */
    public boolean addClassMode(DeviceClassMode deviceClassMode, boolean isOnline, int userId, boolean offLineSend) {
        String content = "添加课堂模式:".concat(deviceClassMode.getSequence().toString());
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(deviceClassMode.getImei(), Constants.SET_NO_DISTURB_TIME, deviceClassMode.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(deviceClassMode.getImei(), Constants.SET_NO_DISTURB_TIME, content, deviceClassMode.getCommandNumber(), userId, deviceClassMode.getSequence());
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(deviceClassMode.getImei(), Constants.SET_NO_DISTURB_TIME, content, userId, JSONObject.toJSONString(deviceClassMode), deviceClassMode.getCommandNumber(), deviceClassMode.getSequence());
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setClassMode(deviceClassMode);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置课堂模式】,【添加】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 删除课堂模式 （免打扰协议）
     *
     * @param imei          设备imei
     * @param commandNumber 指令序列号
     * @param sequence      课堂模式序号
     * @param isOnline      设备是否在线
     * @param userId        操作用户id
     * @return
     */
    public boolean delClassMode(String imei, String commandNumber, int sequence, boolean isOnline, int userId, boolean offLineSend) {
        String content = "删除课堂模式:".concat(String.valueOf(sequence));
        DeviceClassMode deviceClassMode = new DeviceClassMode();
        deviceClassMode.setImei(imei);
        deviceClassMode.setSequence(sequence);
        deviceClassMode.setCommandNumber(commandNumber);
        deviceClassMode.setStartTime("00:00");
        deviceClassMode.setEndTime("00:00");
        deviceClassMode.setRepeatTime("0000000");
        // 删除：关闭该序列号即可
        deviceClassMode.setOnOff(1);
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(deviceClassMode.getImei(), Constants.DEL_CLASS_MODE, deviceClassMode.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(deviceClassMode.getImei(), Constants.DEL_CLASS_MODE, content, deviceClassMode.getCommandNumber(), userId, sequence);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(deviceClassMode.getImei(), Constants.DEL_CLASS_MODE, content, userId, JSONObject.toJSONString(deviceClassMode), deviceClassMode.getCommandNumber(), deviceClassMode.getSequence());
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setClassMode(deviceClassMode);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置课堂模式】,【删除】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 修改课堂模式 （免打扰协议）
     *
     * @param deviceClassMode 课堂模式对象
     * @param isOnline        设备是否在线
     * @param userId          操作用户Id
     * @return
     */
    public boolean updateClassMode(DeviceClassMode deviceClassMode, boolean isOnline, int userId, boolean offLineSend) {
        String content = "修改课堂模式:".concat(String.valueOf(deviceClassMode.getSequence()));
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(deviceClassMode.getImei(), Constants.UPDATE_CLASS_MODE, deviceClassMode.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(deviceClassMode.getImei(), Constants.UPDATE_CLASS_MODE, content, deviceClassMode.getCommandNumber(), userId, deviceClassMode.getSequence());
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(deviceClassMode.getImei(), Constants.UPDATE_CLASS_MODE, content, userId, JSONObject.toJSONString(deviceClassMode), deviceClassMode.getCommandNumber(), deviceClassMode.getSequence());
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setClassMode(deviceClassMode);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置课堂模式】,【修改】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 课堂模式总开关 （免打扰协议）
     *
     * @param imei
     * @param commandNumber
     * @param onOff
     * @return
     */
    public boolean updateClassModeAllSwitch(String imei, String commandNumber, int onOff, boolean isOnline, int userId, boolean offLineSend) {
        String content = "设置课堂模式总开关:".concat(onOff == 1 ? "开" : "关");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SET_NO_DISTURB_SWITCH, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SET_NO_DISTURB_SWITCH, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SET_NO_DISTURB_SWITCH, content, userId, String.valueOf(onOff), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setClassModeSwitch(imei, commandNumber, onOff);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【课堂模式总开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }


    /**
     * 设置PDOP门限
     *
     * @param imei
     * @param commandNumber
     * @param thresholdParam
     * @return
     */
    public boolean setPDOP(String imei, String commandNumber, Integer thresholdParam, boolean isOnline, int userId, boolean offLineSend) {
        String content = "设置PDOP门限值:".concat(thresholdParam.toString());
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SET_PDOP_THRESHOLD_VALUE, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SET_PDOP_THRESHOLD_VALUE, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SET_PDOP_THRESHOLD_VALUE, content, userId, thresholdParam.toString(), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setPDOP(imei, commandNumber, thresholdParam);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置PDOP门限】,【修改】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置SOS开关
     *
     * @param imei
     * @param commandNumber
     * @param onOff
     * @return
     */
    public boolean setSOSSwitch(String imei, String commandNumber, Integer onOff, boolean isOnline, int userId, boolean offLineSend) {
        String content = "设置SOS开关:".concat(onOff == 1 ? "关闭" : "打开");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SET_SOS_DIAL_SWITCH, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SET_SOS_DIAL_SWITCH, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SET_SOS_DIAL_SWITCH, content, userId, onOff.toString(), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setSOSSwitch(imei, commandNumber, onOff);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置SOS开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 恢复出厂设置
     *
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean reSetDevice(String imei, String commandNumber, boolean isOnline, int userId, boolean offLineSend) {
        String content = "恢复出厂设置";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.FACTORY_RESET, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.FACTORY_RESET, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.FACTORY_RESET, content, userId, null, commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.reSetDevice(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【恢复出厂设置】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 重启设备
     *
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean restartDevice(String imei, String commandNumber, Integer userId) {
        String content = "重启设备";
        RespCodeEntity respCodeEntity = irmFeignClientService.reStartDevice(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        if (result) {
            //存储在线发送指令记录
            saveOnlineSendCommandRecord(imei, Constants.DEVICE_RESTART, content, commandNumber, userId, null);
        }
        logger.info("指令【重启设备】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 软件关机
     *
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean shutDownDevice(String imei, String commandNumber, Integer userId) {
        RespCodeEntity respCodeEntity = irmFeignClientService.shutDownDevice(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        if (result) {
            //该指令无回复，直接存储为发送成功指令
            saveSuccessSendCommandRecord(imei, Constants.SOFTWARE_TURN_OFF, "软件关机", commandNumber, userId);
        }
        logger.info("指令【软件关机】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 音量调节
     *
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean adjustVolume(String imei, String commandNumber, Integer speakLevel, boolean isOnline, Integer userId, boolean offLineSend) {
        String content = "音量调节至：".concat(speakLevel.toString());
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.VOLUME_ADJUSTMENT, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.VOLUME_ADJUSTMENT, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.VOLUME_ADJUSTMENT, content, userId, speakLevel.toString(), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.adjustVolume(imei, commandNumber, speakLevel);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【音量调节】,发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设备白名单设置
     *
     * @param deviceWhiteCall
     * @param isOnline
     * @param userId
     * @return
     */
    public boolean addWhiteCall(DeviceWhiteCall deviceWhiteCall, boolean isOnline, Integer userId, boolean offLineSend) {
        String content = "新增白名单：".concat(deviceWhiteCall.getSequence().toString());
        String imei = deviceWhiteCall.getImei();
        String commandNumber = deviceWhiteCall.getCommandNumber();
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SINGLE_WHITELIST_NUMBER, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SINGLE_WHITELIST_NUMBER, content, commandNumber, userId, deviceWhiteCall.getSequence());
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SINGLE_WHITELIST_NUMBER, content, userId, JSONObject.toJSONString(deviceWhiteCall), commandNumber, deviceWhiteCall.getSequence());
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setWhiteCall(deviceWhiteCall);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置白名单】,【增加】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 删除白名单
     *
     * @param
     * @param isOnline
     * @param userId
     * @return
     */
    public boolean delWhiteCall(String imei, String commandNumber, Integer sequence, boolean isOnline, Integer userId, boolean offLineSend) {
        String content = "删除白名单：".concat(sequence.toString());
        DeviceWhiteCall deviceWhiteCall = new DeviceWhiteCall();
        deviceWhiteCall.setImei(imei);
        deviceWhiteCall.setCommandNumber(commandNumber);
        deviceWhiteCall.setSequence(sequence);
        deviceWhiteCall.setName("");
        deviceWhiteCall.setPhone("");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.DEL_WHITE_CALL, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.DEL_WHITE_CALL, content, commandNumber, userId, sequence);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.DEL_WHITE_CALL, content, userId, JSONObject.toJSONString(deviceWhiteCall), commandNumber, deviceWhiteCall.getSequence());
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setWhiteCall(deviceWhiteCall);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置白名单】,【删除】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 更新设备白名单
     *
     * @param deviceWhiteCall
     * @param isOnline
     * @param userId
     * @return
     */
    public boolean updateDeviceWhiteCall(DeviceWhiteCall deviceWhiteCall, boolean isOnline, Integer userId, boolean offLineSend) {
        String content = "更新白名单：".concat(deviceWhiteCall.getSequence().toString());
        String imei = deviceWhiteCall.getImei();
        String commandNumber = deviceWhiteCall.getCommandNumber();
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.UPDATE_WHITE_CALL, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.UPDATE_WHITE_CALL, content, commandNumber, userId, deviceWhiteCall.getSequence());
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.UPDATE_WHITE_CALL, content, userId, JSONObject.toJSONString(deviceWhiteCall), commandNumber, deviceWhiteCall.getSequence());
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setWhiteCall(deviceWhiteCall);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置白名单】,【修改】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 一次性设置所有白名单
     *
     * @param deviceWhiteCallList name：  phone: sequence：
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean setAllWhiteCall(List<Map<String, Object>> deviceWhiteCallList, String imei, String commandNumber, boolean isOnline, Integer userId, boolean offLineSend) {
        String content = "一次性设置所有白名单：";
        MqSetAllWhiteCall mqSetAllWhiteCall = new MqSetAllWhiteCall();
        mqSetAllWhiteCall.setCommandNumber(commandNumber);
        mqSetAllWhiteCall.setImei(imei);
        mqSetAllWhiteCall.setWhiteCallList(deviceWhiteCallList);
        RespCodeEntity respCodeEntity = irmFeignClientService.setAllWhiteCall(mqSetAllWhiteCall);
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.ALL_WHITELIST_NUMBER, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.ALL_WHITELIST_NUMBER, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.ALL_WHITELIST_NUMBER, content, userId, JSONObject.toJSONString(mqSetAllWhiteCall), commandNumber, null);
            }
        }
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【一次性设置所有白名单】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 一次性设置所有sos号码
     */
    public boolean setAllSosCall(List<DeviceSOSList> deviceAllSosCallList, String imei, String commandNumber, boolean isOnline, Integer userId, boolean offLineSend) {
        String content = "一次性设置所有sos号码：";
        MqSetAllSosCall mqSetAllSosCall = new MqSetAllSosCall();
        mqSetAllSosCall.setImei(imei);
        mqSetAllSosCall.setCommandNumber(commandNumber);
        mqSetAllSosCall.setSosCallList(deviceAllSosCallList);
        RespCodeEntity respCodeEntity = irmFeignClientService.setAllSosCallList(mqSetAllSosCall);
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.ALL_SOS_PHONE, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.ALL_SOS_PHONE, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.ALL_SOS_PHONE, content, userId, JSONObject.toJSONString(mqSetAllSosCall), commandNumber, null);
            }
        }
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【一次性设置所有白名单】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }


    /**
     * 设置白名单开关
     *
     * @param imei
     * @param commandNumber
     * @param onOff
     * @return
     */
    public boolean setWhiteCallSwitch(String imei, String commandNumber, Integer onOff, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "设置白名单开关:".concat(onOff == 0 ? "关闭" : "开启");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.WHITELIST_SWITCH, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.WHITELIST_SWITCH, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.WHITELIST_SWITCH, content, userId, onOff.toString(), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setWhiteCallSwitch(imei, commandNumber, onOff);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置白名单开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 获取设备步数
     *
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean getDeviceStep(String imei, String commandNumber, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "获取设备步数";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.GET_DEVICE_STEP, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.GET_DEVICE_STEP, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.GET_DEVICE_STEP, content, userId, null, commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.getStepNum(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【获取步数】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 更新M1卡信息
     *
     * @param imei
     * @param commandNumber
     * @param m1Card
     * @return
     */
    public boolean updateM1Card(String imei, String commandNumber, String m1Card, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "更新M1Card为：".concat(m1Card);
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.RESET_M1_CARD, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.RESET_M1_CARD, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.RESET_M1_CARD, content, userId, m1Card, commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.updateM1Card(imei, commandNumber, m1Card);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【修改设备M1卡号】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 切换设备id
     *
     * @param imei
     * @param commandNumber
     * @param idFlag
     * @return
     */
    public boolean exchangeDeviceId(String imei, String commandNumber, Integer idFlag, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "更改设备ID为：".concat(idFlag == 0 ? "IMEID" : "ICCID");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.CHANGE_DEVICE_ID, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.CHANGE_DEVICE_ID, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.CHANGE_DEVICE_ID, content, userId, idFlag.toString(), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.exchangeDeviceId(imei, commandNumber, idFlag);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【修改设备M1卡号】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 清除绑定信息
     *
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean cleanBandingMess(String imei, String commandNumber, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "更改设备ID为：";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.REMOVE_BINDING, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.REMOVE_BINDING, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.REMOVE_BINDING, content, userId, null, commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.cleanSim(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【清除绑定信息】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置关机静默
     *
     * @param imei
     * @param commandNumber
     * @return
     */
    public boolean setShutDownSilent(Integer flag, String imei, String commandNumber, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "设置关机静默为：".concat(flag.toString());
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SHUT_DOWN_SILENT, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SHUT_DOWN_SILENT, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SHUT_DOWN_SILENT, content, userId, flag.toString(), commandNumber, null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.cleanSim(imei, commandNumber);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置关机静默】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 给喜马拉雅设备发送绑定关系
     *
     * @param data
     * @param userId
     * @param isOnline
     * @param offLineSend
     * @return
     */
    public boolean sendBindingStatus(JSONObject data, Integer userId, boolean isOnline, boolean offLineSend) {
        String content = "XMLY设备发送绑定关系,imei：" + data.getString("imei");
        String imei = data.getString("imei");
        String commandNumber = data.getString("commandNumber");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.DEVICE_BINDING_STATUS, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.DEVICE_BINDING_STATUS, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.DEVICE_BINDING_STATUS, content, userId, JSONObject.toJSONString(data), commandNumber, null);
            }
        }
        DeviceBindingStatus binding = new DeviceBindingStatus();
        binding.setImei(imei);
        binding.setCommandNumber(commandNumber);
        binding.setClassesName(data.getString("gradeName").concat(data.getString("classesName")));
        binding.setSchoolName(data.getString("schoolName"));
        binding.setStudentName(data.getString("studentName"));
        binding.setStatus(data.getInteger("status"));
        logger.info("/下发绑定状态的信息为:" + binding.toString());
        RespCodeEntity respCodeEntity = irmFeignClientService.setBindingStatus(binding);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置绑定状态】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设备设置闹钟
     *
     * @param data
     * @param userId
     * @param isOnline
     * @param offLineSend
     * @return
     */
    public boolean setAlarm(DeviceAlarm data, Integer userId, boolean isOnline, boolean offLineSend) {
        String imei = data.getImei();
        String content = "设置闹钟,imei：" + imei;
        String commandNumber = data.getCommandNumber();
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.ALARM_CLOCK, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.ALARM_CLOCK, content, commandNumber, userId, data.getSequence());
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.ALARM_CLOCK, content, userId, JSONObject.toJSONString(data), commandNumber, data.getSequence());
            }
        }
        logger.info("/设备闹钟设置的信息为:" + data.toString());
        RespCodeEntity respCodeEntity = irmFeignClientService.setAlarm(data);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【设置闹钟】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 删除设备闹钟
     *
     * @param data
     * @param userId
     * @param isOnline
     * @param offLineSend
     * @return
     */
    public boolean deleteAlarm(JSONObject data, Integer userId, boolean isOnline, boolean offLineSend) {
        String imei = data.getString("imei");
        Integer sequence = data.getInteger("sequence");
        String commandNumber = data.getString("commandNumber");
        String content = "删除序列号为" + sequence + "的闹钟,imei：" + imei;
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.DELETE_CLOCK, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.DELETE_CLOCK, content, commandNumber, userId, sequence);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.DELETE_CLOCK, content, userId, JSONObject.toJSONString(data), commandNumber, sequence);
            }
        }
        logger.info("/删除闹钟的信息为:" + data.toString());
        RespCodeEntity respCodeEntity = irmFeignClientService.deleteAlarm(imei, commandNumber, String.valueOf(sequence));
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【删除闹钟】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 下发文本信息
     *
     * @param data
     * @param userId
     * @param isOnline
     * @param offLineSend
     * @return
     */
    public boolean sendText(MqTextData data, Integer userId, boolean isOnline, boolean offLineSend) {
        String imei = data.getImei();
        String commandNumber = data.getCommandNumber();
        String content = "发送文本，imei:" + imei;
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SEND_TEXT, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SEND_TEXT, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SEND_TEXT, content, userId, JSONObject.toJSONString(data), commandNumber, null);
            }
        }
        logger.info("/发送文本内容为:" + data.toString());
        RespCodeEntity respCodeEntity = irmFeignClientService.sendText(data);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【下发文本】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }


    /**
     * 下发文本信息（用于批量下发）
     *
     * @param data
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean sendText2(MqTextData data, Integer userId, boolean offLineSend) {
        String imei = data.getImei();
        boolean isOnline = deviceOnline(imei);
        String commandNumber = data.getCommandNumber();
        String content = "发送文本，imei:" + imei;
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(imei, Constants.SEND_TEXT, commandNumber);
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(imei, Constants.SEND_TEXT, content, commandNumber, userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(imei, Constants.SEND_TEXT, content, userId, JSONObject.toJSONString(data), commandNumber, null);
            }
        }
        logger.info("/发送文本内容为:" + data.toString());
        RespCodeEntity respCodeEntity = irmFeignClientService.sendText(data);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【下发文本】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * app应用安装总开关
     *
     * @param mqAppInstallationSwitch
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean appInstallationSwitch(MqAppInstallationSwitch mqAppInstallationSwitch, boolean isOnline, int userId, boolean offLineSend) {
        String content = "app应用安装总开关".concat(mqAppInstallationSwitch.getOnOff() == 1 ? "开" : "关");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqAppInstallationSwitch.getImei(), Constants.APP_INSTALLATION, mqAppInstallationSwitch.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqAppInstallationSwitch.getImei(), Constants.APP_INSTALLATION, content, mqAppInstallationSwitch.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqAppInstallationSwitch.getImei(), Constants.APP_INSTALLATION, content, userId, JSONObject.toJSONString(mqAppInstallationSwitch), mqAppInstallationSwitch.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.appInstallationSwitch(mqAppInstallationSwitch);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【app应用安装总开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * app禁用指令
     *
     * @param mqAppDisable
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean appDisable(MqAppDisable mqAppDisable, boolean isOnline, int userId, boolean offLineSend) {
        String content = "禁用包名为" + mqAppDisable.getPackageName() + "[开关状态:".concat(mqAppDisable.getFlag() == 1 ? "开" : "关]");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqAppDisable.getImei(), Constants.APP_DISABLE.concat("-").concat(mqAppDisable.getPackageName()), mqAppDisable.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqAppDisable.getImei(), Constants.APP_DISABLE.concat("-").concat(mqAppDisable.getPackageName()), content, mqAppDisable.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqAppDisable.getImei(), Constants.APP_DISABLE.concat("-").concat(mqAppDisable.getPackageName()), content, userId, JSONObject.toJSONString(mqAppDisable), mqAppDisable.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.appDisable(mqAppDisable);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【app禁用开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置锁网指令
     *
     * @param mqLockNet
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean setlockNet(MqLockNet mqLockNet, boolean isOnline, int userId, boolean offLineSend) {
        String content = "锁网指令开关".concat(mqLockNet.getFlag() == 1 ? "开" : "关");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqLockNet.getImei(), Constants.LOCK_NET, mqLockNet.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqLockNet.getImei(), Constants.LOCK_NET, content, mqLockNet.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqLockNet.getImei(), Constants.LOCK_NET, content, userId, JSONObject.toJSONString(mqLockNet), mqLockNet.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setLockNet(mqLockNet);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【锁网指令开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置锁卡
     *
     * @param mqLockCard
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean setLockCard(MqLockCard mqLockCard, boolean isOnline, int userId, boolean offLineSend) {
        String content = "锁卡指令开关".concat(mqLockCard.getFlag() == 1 ? "开" : "关");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqLockCard.getImei(), Constants.LOCK_CARD, mqLockCard.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqLockCard.getImei(), Constants.LOCK_CARD, content, mqLockCard.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqLockCard.getImei(), Constants.LOCK_CARD, content, userId, JSONObject.toJSONString(mqLockCard), mqLockCard.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setLockCard(mqLockCard);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【锁卡指令开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 设置锁机
     *
     * @param mqLockDevice
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean setLockDevice(MqLockDevice mqLockDevice, boolean isOnline, int userId, boolean offLineSend) {
        String content = "锁机指令开关".concat(mqLockDevice.getFlag() == 1 ? "开" : "关");
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqLockDevice.getImei(), Constants.LOCK_DEVICE, mqLockDevice.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqLockDevice.getImei(), Constants.LOCK_DEVICE, content, mqLockDevice.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqLockDevice.getImei(), Constants.LOCK_DEVICE, content, userId, JSONObject.toJSONString(mqLockDevice), mqLockDevice.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.setLockDevice(mqLockDevice);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【锁机指令开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }


    /**
     * 同步设备服务器之间的锁网状态
     *
     * @param mqGetLockNet
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean getLockNet(MqGetLockNet mqGetLockNet, boolean isOnline, int userId, boolean offLineSend) {
        String content = "查询锁网";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqGetLockNet.getImei(), Constants.GET_LOCK_NET, mqGetLockNet.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqGetLockNet.getImei(), Constants.GET_LOCK_NET, content, mqGetLockNet.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqGetLockNet.getImei(), Constants.GET_LOCK_NET, content, userId, JSONObject.toJSONString(mqGetLockNet), mqGetLockNet.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.getLockNet(mqGetLockNet);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【锁机指令开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 同步锁卡状态
     *
     * @param mqGetLockCard
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean getLockCard(MqGetLockCard mqGetLockCard, boolean isOnline, int userId, boolean offLineSend) {
        String content = "查询锁卡";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqGetLockCard.getImei(), Constants.GET_LOCK_CARD, mqGetLockCard.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqGetLockCard.getImei(), Constants.GET_LOCK_CARD, content, mqGetLockCard.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqGetLockCard.getImei(), Constants.GET_LOCK_CARD, content, userId, JSONObject.toJSONString(mqGetLockCard), mqGetLockCard.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.getLockCard(mqGetLockCard);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【锁机指令开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /**
     * 同步锁机状态
     *
     * @param mqGetLockDevice
     * @param isOnline
     * @param userId
     * @param offLineSend
     * @return
     */
    public boolean getLockDevice(MqGetLockDevice mqGetLockDevice, boolean isOnline, int userId, boolean offLineSend) {
        String content = "查询锁机";
        if (offLineSend) {
            //将指令记录表中的该条离线发送类型记录的结果改为发送中，并写入开始时间
            modifyOfflineCommandRecord(mqGetLockDevice.getImei(), Constants.GET_LOCK_DEVICE, mqGetLockDevice.getCommandNumber());
        } else {
            if (isOnline) {
                //存储在线发送指令记录
                saveOnlineSendCommandRecord(mqGetLockDevice.getImei(), Constants.GET_LOCK_DEVICE, content, mqGetLockDevice.getCommandNumber(), userId, null);
            } else {  // 当做离线指令处理
                return saveOffLineBufferAndCommandRecord(mqGetLockDevice.getImei(), Constants.GET_LOCK_DEVICE, content, userId, JSONObject.toJSONString(mqGetLockDevice), mqGetLockDevice.getCommandNumber(), null);
            }
        }
        RespCodeEntity respCodeEntity = irmFeignClientService.getLockDevice(mqGetLockDevice);
        boolean result = respCodeEntity.getCode() == RespCode.SUCCESS.getCode();
        logger.info("指令【锁机指令开关】发送到RocketMQ : {}", result ? "成功" : "失败");
        return result;
    }

    /***
     * 保存离线缓存指令
     * @param imei 设备imei号
     * @param cmd 指令关键字
     * @param param 指令参数
     * @param userId 操作用户
     * @return 插入结果
     */
    private int saveOffLineBufferCmd(String imei, String cmd, String param, Integer sequence, Integer userId) {
        OffLineBufferCmd offLineBufferCmd = new OffLineBufferCmd();
        offLineBufferCmd.setCmd(cmd);
        offLineBufferCmd.setImei(imei);
        offLineBufferCmd.setParam(param);
        offLineBufferCmd.setUser_id(userId);
        offLineBufferCmd.setSequence(sequence);
        offLineBufferCmd.setSave_time(System.currentTimeMillis());
        // 插入一笔离线缓存指令记录
        int i = offLineBufferCmdMapper.saveOffLineBufferCmd(offLineBufferCmd);
        return i == 0 ? 0 : offLineBufferCmd.getId();
    }

    /**
     * 保存发送记录
     *
     * @param imei          设备imei
     * @param cmd           指令关键字
     * @param content       指令内容
     * @param commandNumber 指令流水号
     * @param userId        操作用户id
     * @return 保存行数
     */
    private void saveOnlineSendCommandRecord(String imei, String cmd, String content, String commandNumber, Integer userId, Integer seq) {
        CommandRecord commandRecord = new CommandRecord();
        commandRecord.setDeviceImei(imei);
        commandRecord.setCommandType(cmd);
        commandRecord.setCommandContent(content);
        commandRecord.setCommandNumber(commandNumber);
        commandRecord.setBeginTime(System.currentTimeMillis());
        commandRecord.setResult(Constants.COMMAND_SENDING);
        commandRecord.setUserId(userId);
        commandRecord.setSequence(seq);
        commandRecord.setSendType(Constants.COMMAND_ONLINE);
        commandRecordMapper.saveCommandRecord(commandRecord);
    }

    private void saveSuccessSendCommandRecord(String imei, String cmd, String content, String commandNumber, Integer userId) {
        CommandRecord commandRecord = new CommandRecord();
        commandRecord.setDeviceImei(imei);
        commandRecord.setCommandType(cmd);
        commandRecord.setCommandContent(content);
        commandRecord.setCommandNumber(commandNumber);
        commandRecord.setBeginTime(System.currentTimeMillis());
        commandRecord.setEndTime(System.currentTimeMillis());
        commandRecord.setResult(Constants.COMMAND_COMPLETE);
        commandRecord.setUserId(userId);
        commandRecord.setSendType(Constants.COMMAND_ONLINE);
        commandRecordMapper.saveCommandRecord(commandRecord);
    }

    /**
     * 保存发送记录
     *
     * @param imei          设备imei
     * @param cmd           指令关键字
     * @param content       指令内容
     * @param commandNumber 指令流水号
     * @param userId        操作用户id
     */
    private void saveOfflineSendCommandRecord(String imei, String cmd, String content, String commandNumber, Integer userId, Integer offlineId, Integer sequence) {
        CommandRecord commandRecord = new CommandRecord();
        commandRecord.setDeviceImei(imei);
        commandRecord.setCommandType(cmd);
        commandRecord.setCommandContent(content);
        commandRecord.setCommandNumber(commandNumber);
        commandRecord.setResult(Constants.COMMAND_WAITING_SEND);
        commandRecord.setUserId(userId);
        commandRecord.setSendType(Constants.COMMAND_OFFLINE);
        commandRecord.setCreateTime(System.currentTimeMillis());
        commandRecord.setOfflineId(offlineId);
        commandRecord.setSequence(sequence);
        commandRecordMapper.saveOfflineCommandRecord(commandRecord);
    }


    /**
     * 修改指令下发表中离线发送指令的发送状态
     *
     * @param imei
     * @param contentType
     * @param commandNumber
     * @return
     */
    public void modifyOfflineCommandRecord(String imei, String contentType, String commandNumber) {
        CommandRecord record = commandRecordMapper.getNotCompleteCommandRecordByCondition(imei, contentType, commandNumber);
        record.setBeginTime(System.currentTimeMillis());//设置指令开始时间
        record.setResult(Constants.COMMAND_SENDING);//设置指令状态为发送中
        commandRecordMapper.modifyOffLineSendCommand(record);
    }

    /**
     * 存储离线指令信息
     *
     * @param imei
     * @param commandType
     * @param commandContent
     * @param userId
     * @param param
     * @param commandNumber
     * @return
     */
    public boolean saveOffLineBufferAndCommandRecord(String imei, String commandType, String commandContent, Integer userId, String param, String commandNumber, Integer sequence) {
        //存储离线指令
        OffLineBufferCmd offLineBuffer = offLineBufferCmdMapper.selectOffLineBufferCmd(imei, commandType, sequence);
        if (offLineBuffer == null) {
            //向离线指令缓存表中添加一笔数据
            int offlineId = saveOffLineBufferCmd(imei, commandType, param, sequence, userId);
            //向指令下发记录表中添加一笔数据
            if (offlineId == 0) {
                return false;
            }
            saveOfflineSendCommandRecord(imei, commandType, commandContent, commandNumber, userId, offlineId, sequence);
        } else {
            //修改离线缓存指令表和指令下发记录表中离线发送记录的数据
            offLineBuffer.setSave_time(System.currentTimeMillis());
            offLineBuffer.setParam(param);
            Integer i1 = offLineBufferCmdMapper.modifyOffLineBufferCmd(offLineBuffer);
            CommandRecord commandRecord = new CommandRecord();
            commandRecord.setCreateTime(System.currentTimeMillis());
            commandRecord.setCommandNumber(commandNumber);
            commandRecord.setOfflineId(offLineBuffer.getId());
            commandRecord.setUserId(userId);
            commandRecord.setSequence(sequence);
            Integer i2 = commandRecordMapper.modifyOffLineCommandRecordParam(commandRecord);
            return i1 + i2 > 0;
        }
        return true;
    }


    /**
     * 离线指令的发送
     *
     * @param type
     * @param param
     * @param imei
     */
    public void sendOffLineCommand(String type, String param, String imei, Integer userId, String commandNumber) {
        if (Constants.DEVICE_PARAMETERS.equals(type)) {
            getDeviceParam(imei, commandNumber, userId, true, true);
        } else if (Constants.ICCID_AND_SIM.equals(type)) {
            getDeviceIccidAndSimCardNo(imei, commandNumber, userId, true, true);
        } else if (Constants.DEVICE_IMEID.equals(type)) {
            getDeviceImeid(imei, commandNumber, userId, true, true);
        } else if (Constants.SET_TEMPORARY_CONTROL_CENTER.equals(type)) {
            MqSetIpAndPort data = JSON.parseObject(param, MqSetIpAndPort.class);
            setTempServerIpAndPort(imei, data.getCommandNumber(), data.getIpAddress(), data.getPort(), userId, true, true);
        } else if (Constants.SET_DEFAULT_CONTROL_CENTER.equals(type)) {
            MqSetIpAndPort data = JSON.parseObject(param, MqSetIpAndPort.class);
            setDefaultServerIpAndPort(imei, data.getCommandNumber(), data.getIpAddress(), data.getPort(), true, userId, true);
        } else if (Constants.SET_WORK_MODE.equals(type)) {
            MqSetWorkMode data = JSON.parseObject(param, MqSetWorkMode.class);
            setDeviceMode(imei, data.getCommandNumber(), data.getMode(), data.getInterval(), true, userId, true);
        } else if (Constants.SET_UPLOAD_TIME.equals(type)) {
            Integer interval = Integer.parseInt(param);
            setUploadInterval(imei, commandNumber, interval, true, userId, true);
        } else if (Constants.AUTO_CHANGE_WORK_MODE.equals(type)) {
            MqSleepTimeAutoChange data = JSON.parseObject(param, MqSleepTimeAutoChange.class);
            setSleepTimeAutoChangeMode(imei, data.getCommandNumber(), data.getStart(), data.getEnd(), data.getFlag(), true, userId, true);
        } else if (Constants.SET_NO_DISTURB_TIME.equals(type)) {
            DeviceClassMode data = JSON.parseObject(param, DeviceClassMode.class);
            addClassMode(data, true, userId, true);
        } else if (Constants.DEL_CLASS_MODE.equals(type)) {
            DeviceClassMode data = JSON.parseObject(param, DeviceClassMode.class);
            delClassMode(data.getImei(), data.getCommandNumber(), data.getSequence(), true, userId, true);
        } else if (Constants.UPDATE_CLASS_MODE.equals(type)) {
            DeviceClassMode data = JSON.parseObject(param, DeviceClassMode.class);
            updateClassMode(data, true, userId, true);
        } else if (Constants.SET_NO_DISTURB_SWITCH.equals(type)) {
            Integer data = Integer.parseInt(param);
            updateClassModeAllSwitch(imei, commandNumber, data, true, userId, true);
        } else if (Constants.SET_PDOP_THRESHOLD_VALUE.equals(type)) {
            Integer data = Integer.parseInt(param);
            setPDOP(imei, commandNumber, data, true, userId, true);
        } else if (Constants.SET_SOS_DIAL_SWITCH.equals(type)) {
            Integer data = Integer.parseInt(param);
            setSOSSwitch(imei, commandNumber, data, true, userId, true);
        } else if (Constants.FACTORY_RESET.equals(type)) {
            reSetDevice(imei, commandNumber, true, userId, true);
        } else if (Constants.VOLUME_ADJUSTMENT.equals(type)) {
            Integer data = Integer.parseInt(param);
            adjustVolume(imei, commandNumber, data, true, userId, true);
        } else if (Constants.SINGLE_WHITELIST_NUMBER.equals(type)) {
            DeviceWhiteCall data = JSON.parseObject(param, DeviceWhiteCall.class);
            addWhiteCall(data, true, userId, true);
        } else if (Constants.DEL_WHITE_CALL.equals(type)) {
            DeviceWhiteCall data = JSON.parseObject(param, DeviceWhiteCall.class);
            delWhiteCall(data.getImei(), data.getCommandNumber(), data.getSequence(), true, userId, true);
        } else if (Constants.UPDATE_WHITE_CALL.equals(type)) {
            DeviceWhiteCall data = JSON.parseObject(param, DeviceWhiteCall.class);
            updateDeviceWhiteCall(data, true, userId, true);
        } else if (Constants.ALL_WHITELIST_NUMBER.equals(type)) {
            MqSetAllWhiteCall data = JSON.parseObject(param, MqSetAllWhiteCall.class);
            setAllWhiteCall(data.getWhiteCallList(), data.getImei(), data.getCommandNumber(), true, userId, true);
        } else if (Constants.WHITELIST_SWITCH.equals(type)) {
            Integer onOff = Integer.parseInt(param);
            setWhiteCallSwitch(imei, commandNumber, onOff, userId, true, true);
        } else if (Constants.GET_DEVICE_STEP.equals(type)) {
            getDeviceStep(imei, commandNumber, userId, true, true);
        } else if (Constants.RESET_M1_CARD.equals(type)) {
            updateM1Card(imei, commandNumber, param, userId, true, true);
        } else if (Constants.DEVICE_BINDING_STATUS.equals(type)) {
            JSONObject data = JSON.parseObject(param);
            sendBindingStatus(data, userId, true, true);
        } else if (Constants.ALARM_CLOCK.equals(type)) {
            DeviceAlarm deviceAlarm = JSON.parseObject(param, DeviceAlarm.class);
            setAlarm(deviceAlarm, userId, true, true);
        } else if (Constants.DELETE_CLOCK.equals(type)) {
            JSONObject deviceAlarm = JSON.parseObject(param, JSONObject.class);
            deleteAlarm(deviceAlarm, userId, true, true);
        } else if (Constants.APP_INSTALLATION.equals(type)) {
            MqAppInstallationSwitch mqAppInstallationSwitch = JSON.parseObject(param, MqAppInstallationSwitch.class);
            appInstallationSwitch(mqAppInstallationSwitch, true, userId, true);
        } else if (type.startsWith(Constants.APP_DISABLE)) {
            MqAppDisable mqAppDisable = JSON.parseObject(param, MqAppDisable.class);
            appDisable(mqAppDisable, true, userId, true);
        } else if (Constants.LOCK_NET.equals(type)) {
            MqLockNet mqLockNet = JSON.parseObject(param, MqLockNet.class);
            setlockNet(mqLockNet, true, userId, true);
        } else if (Constants.LOCK_DEVICE.equals(type)) {
            MqLockDevice mqLockDevice = JSON.parseObject(param, MqLockDevice.class);
            setLockDevice(mqLockDevice, true, userId, true);
        } else if (Constants.LOCK_CARD.equals(type)) {
            MqLockCard mqLockCard = JSON.parseObject(param, MqLockCard.class);
            setLockCard(mqLockCard, true, userId, true);
        }
    }


}
